package com.goodomen.garbage.web.config;


import com.goodomen.garbage.web.web.interceptor.BackInterceptor;
import com.goodomen.garbage.web.web.interceptor.JwtInterceptor;
import com.goodomen.garbage.web.web.interceptor.PermissionInterceptor;
import com.goodomen.garbage.web.web.interceptor.RegisterInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Resource
    private JwtInterceptor jwtInterceptor;
    @Resource
    private BackInterceptor loginInterceptor;
    @Resource
    private PermissionInterceptor permissionInterceptor;
    @Resource
    private RegisterInterceptor registerInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor)
                .addPathPatterns("/back/**")
                .excludePathPatterns("/back/sysAdmin/login/**")
                .order(1);
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/back/**")
                .order(2);
        registry.addInterceptor(registerInterceptor)
                .addPathPatterns("/user/register/**")
                .order(3);
        registry.addInterceptor(permissionInterceptor)
                .order(4);

    }
}
